package com.wuwei.elearning.question.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuwei.elearning.question.domain.Question;
import com.wuwei.elearning.question.domain.QuestionTranslated;
import com.wuwei.elearning.question.mapper.QuestionTranslatedMapper;
import com.wuwei.elearning.question.service.QuestionTranslatedService;
import com.wuwei.elearning.setting.mapper.UserMapper;
import com.wuwei.elearning.utils.RecordUtils;
import com.wuwei.elearning.utils.result.Result;
import com.wuwei.elearning.utils.token.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
@RequestMapping("/elearning/QuestionTranslated")
@CrossOrigin
public class QuestionTranslatedController {

    @Resource
    private QuestionTranslatedMapper questionTranslatedMapper;

    @GetMapping("getByQuestionId/{questionId}")
    public Result<QuestionTranslated> getByQuestionId(@PathVariable Integer questionId){
        QuestionTranslated questionTranslated = questionTranslatedMapper.selectOne(new LambdaQueryWrapper<QuestionTranslated>().eq(QuestionTranslated::getQuestionId, questionId));
        return Result.ok(questionTranslated);
    }

    @Resource
    private QuestionTranslatedService questionTranslatedService;

    @PostMapping("edit")
    public Result<String> edit(@RequestBody QuestionTranslated questionTranslated, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        Long account = TokenUtil.getAccountFromToken(token);
        questionTranslatedService.myUpdate(questionTranslated,account);
        return Result.ok("英文版本题目修改成功");
    }
}
